+function (c) {
    var ImgCaptcha = function (f, e) {
        this.$element = c(f);
        this.options = c.extend({}, ImgCaptcha.DEFAULTS, e);
        this.init()
    };
    ImgCaptcha.VERSION = "1.0.0";
    ImgCaptcha.DEFAULTS = {};
    ImgCaptcha.prototype.init = function () {
        var h = this;
        var e = this.$element;
        var f = this.options;
        e.attr("autocomplete", "off");
        e.attr("placeholder", "验证码...看不清点击图片可刷新");
        if (f.ruleRemote == undefined) {
            e.attr("data-rule-remote", Bolt.smartParseURL("/pub/captcha/touch-validate"));
            e.attr("data-msg-remote", "验证码不正确");
            e.attr("data-rule-minlength", 4);
            e.attr("data-msg-minlength", "请输入4位验证码");
            e.attr("data-rule-maxlength", 4);
            e.attr("data-msg-maxlength", "请输入4位验证码")
        }
        e.wrap('<div class="input-group"></div>');
        var g = c('<img alt="验证码" class="captcha-img pull-right" style="height: 34px;width: 110px" title="看不清？点击刷新"/>');
        g.attr("src", Bolt.smartParseURL("/assets/images/captcha_placeholder.jpg"));
        e.after(c('<span class="input-group-btn" style="cursor: pointer;padding-left: 10px"></span>').append(g));
        if (f.inputIcon) {
            if ("true" == f.inputIcon || f.inputIcon === true) {
                f.inputIcon = "fa-qrcode"
            }
            e.wrap('<div class="input-icon"></div>');
            e.before("<i class='fa " + f.inputIcon + "'></i>");
            e.attr("data-input-icon-done", "true")
        }
        this.$captchaImage = g;
        g.on("click", function () {
            h.refresh()
        });
        e.on("focus", function () {
            if (g.attr("src").endsWith("captcha_placeholder.jpg")) {
                h.refresh()
            }
        })
    };
    ImgCaptcha.prototype.refresh = function () {
        var e = this;
        e.$captchaImage.attr("src", Bolt.smartParseURL("/pub/captcha?_=" + new Date().getTime()));
        e.$element.focus().select()
    };
    function Plugin(e) {
        return this.each(function () {
            var h = c(this);
            var g = h.data("ExtImageCaptchaCode");
            var f = typeof e == "object" && e;
            if (!g) {
                h.data("ExtImageCaptchaCode", (g = new ImgCaptcha(this, f)))
            }
            if (typeof e == "string") {
                g[e]()
            }
        })
    }

    $.fn.imgcaptcha = Plugin
    $.fn.imgcaptcha.Constructor = ImgCaptcha;
    $.fn.imgcaptcha.defaults = ImgCaptcha.DEFAULTS;

    $(document).on(Bolt.eventType.initUI, function(e) {
        $(e.target).find('input[data-toggle="captcha-code"]').each(function() {
            var $this = $(this), options = $this.data()
            if (!$this.length) return
            if (options.options && typeof options.options === 'string') options.options = options.options.toObj()
            $.extend(options, typeof options.options === 'object' && options.options)
            Plugin.call($this, options)
        })
    })
}(jQuery);